package com.engine.jz.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.ContentType;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.impl.Service;
import com.engine.jz.service.JzjgService;
import com.engine.jz.util.CommonUtil;
import com.engine.jz.util.KsUtils;
import com.engine.jz.util.TelpoUtils;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;

/**
 * @version 1.0
 * @Title ecology-9
 * @Company 泛微软件
 * @CreateDate 2024/11/27
 * @Description
 * @Author AdminZm
 */
public class JzjgServiceImpl extends Service implements JzjgService {

    BaseBean baseBean = new BaseBean();

    @Override
    public Map<String, Object> handlePushData(Map<String, Object> params) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", "00");
        baseBean.writeLog("handlePushData start.");
        RecordSet rs = new RecordSet();
        Object taskId = null;
        try {
            if (CollectionUtils.isEmpty(params)) {
                baseBean.writeLog("handlePushData params is null.");
                return resultMap;
            }
//            baseBean.writeLog("handlePushData params is:" + JSONObject.toJSONString(params));
            taskId = params.get("taskId");
            if (taskId != null) {
                rs.executeUpdate("UPDATE uf_kqsjtbjlb SET sfysb = 1 WHERE rwid = ?", taskId);
            }
            Object sn = params.get("SN");
            if (sn == null) {
                return resultMap;
            }

            // 判断天波设备是否作为考勤设备
            String idT = null;
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE sblx = 0 AND sbip is not null AND sftskqsj = 0 AND sbxlh = '" + sn + "'");
            while (rs.next()) {
                idT = rs.getString("id");
            }
            if (StringUtils.isEmpty(idT) || new BigDecimal(idT).compareTo(BigDecimal.ZERO) <= 0) {
                return resultMap;
            }

            Object data = params.get("data");
            if (data == null) {
                return resultMap;
            }
//            String dataStr = data.toString();
//            Gson gson = new Gson();
//            Type type = new TypeToken<List<Map<String, String>>>() {}.getType();
//            List<Map<String, String>> mapList = gson.fromJson(dataStr, type);
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) data;

            if (CollectionUtils.isEmpty(mapList)) {
                return resultMap;
            }
            baseBean.writeLog("handlePushData mapList is:" + mapList.size());
            // 获取工号与id对应
            Map<String, String> ghAndIdMap = new HashMap<>();
            rs.execute("SELECT id, loginid FROM hrmresource WHERE loginid is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("loginid");
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                workcode = CommonUtil.removeLeadingZeros(workcode);
                if (StringUtils.isEmpty(workcode)) {
                    continue;
                }
                ghAndIdMap.put(workcode, id);
            }
            if (CollectionUtils.isEmpty(ghAndIdMap)) {
                return resultMap;
            }

            String fromType = "telpo";

//            String sql = "select * from HrmScheduleSign where signFrom = ?";
//            rs.executeQuery(sql, fromType);
//            Set<String> signSet = new HashSet<>();
//            while (rs.next()) {
//                String userId = rs.getString("userId");
//                String signDate = rs.getString("signDate");
//                String signTime = rs.getString("signTime");
//                String signFrom = rs.getString("signFrom");
//                if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(signDate) || StringUtils.isEmpty(signTime) || StringUtils.isEmpty(signFrom)) {
//                    continue;
//                }
//                if (!StringUtils.equals(signFrom, fromType)) {
//                    continue;
//                }
//                signSet.add(userId + "_" + signDate + "_" + signTime + "_" + signFrom);
//            }

            RecordSet rs1 = new RecordSet();

            Set<String> needFormatSet = new HashSet<>();
            List<List> insertList = new ArrayList<>();
            for (Map<String, Object> map : mapList) {
                Object pinObj = map.get("pin");
                Object timeObj = map.get("time");
                if (Objects.isNull(pinObj) || Objects.isNull(timeObj)) {
                    continue;
                }
                String pin = pinObj.toString();
                pin = CommonUtil.removeLeadingZeros(pin);
                if (StringUtils.isEmpty(pin)) {
                    continue;
                }
                String time = timeObj.toString();
                if (StringUtils.isEmpty(pin) || StringUtils.isEmpty(time)) {
                    continue;
                }
                if (pin.length() == 4 && pin.startsWith("9")) {
                    pin = "90" + pin;
                }
                String id = ghAndIdMap.get(pin);
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                baseBean.writeLog("handlePushData time:" + time + "、" + pin);
                String[] dt = time.split(" ");
                if (dt.length < 2) {
                    dt = time.split("=");
                    if (dt.length < 2) {
                        continue;
                    }
                }
                String rq = dt[0];
                String sj = dt[1];
                rs1.execute("select userId from HrmScheduleSign where signFrom = '" + fromType + "' and userId = " + id +
                        " and signDate = '" + rq + "' and signTime = '" + sj + "'");
                if (rs1.next()) {
                    String userIdTemp = rs1.getString("userId");
                    if (StringUtils.isNotEmpty(userIdTemp)) {
                        continue;
                    }
                }
//                String keyTemp = id + "_" + rq + "_" + sj + "_" + fromType;
//                if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
//                    continue;
//                }
                List list = new ArrayList();
                list.add(id);
                list.add("1");
                list.add(rq);
                list.add(sj);
                list.add("1");
                list.add(fromType);
                list.add(rq);
                Map<String, Object> mapT = new HashMap<>();
                mapT.put("deviceId", sn);
                list.add(JSONObject.toJSONString(mapT));
                insertList.add(list);
                needFormatSet.add(id + "_" + rq);
            }

            if (!CollectionUtils.isEmpty(insertList)) {
                String insertSql = "INSERT INTO HrmScheduleSign(userId, userType, signDate, signTime, isInCom, " +
                        "signFrom, belongdate, deviceinfo) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
                rs.executeBatchSql(insertSql, insertList);
            }
            baseBean.writeLog("handlePushData end.");
//            baseBean.writeLog("handlePushData needFormatSet:" + needFormatSet);
//            if (!CollectionUtils.isEmpty(needFormatSet)) {
//                for (String key : needFormatSet) {
//                    String yg = key.split("_")[0];
//                    String rq = key.split("_")[1];
//                    new KQFormatBiz().formatDate(yg, rq);
//                    SplitActionUtil.pushOverTimeTasksAll(rq, rq, "" + yg);
//                }
//            }
        } catch (Exception e) {
            if (taskId != null) {
                rs.executeUpdate("UPDATE uf_kqsjtbjlb SET sbclyc = ? WHERE rwid = ?", e.getMessage(), taskId);
            }
            baseBean.writeLog("handlePushData error:" + e);
        }

        return resultMap;
    }

    @Override
    public Map<String, Object> handleNowPushData(Map<String, Object> params) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", "00");
        baseBean.writeLog("handleNowPushData start.");
        RecordSet rs = new RecordSet();
        try {
            if (CollectionUtils.isEmpty(params)) {
                baseBean.writeLog("handleNowPushData params is null.");
                return resultMap;
            }
            Object sn = params.get("SN");
            if (sn == null) {
                return resultMap;
            }

            // 判断天波设备是否作为考勤设备
            String idT = null;
            rs.execute("SELECT id FROM uf_kqsbdzgxgljmb WHERE sblx = 0 AND sbip is not null AND sftskqsj = 0 AND sbxlh = '" + sn + "'");
            while (rs.next()) {
                idT = rs.getString("id");
            }
            if (StringUtils.isEmpty(idT) || new BigDecimal(idT).compareTo(BigDecimal.ZERO) <= 0) {
                return resultMap;
            }

            Object data = params.get("data");
            if (data == null) {
                return resultMap;
            }
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) data;
            if (CollectionUtils.isEmpty(mapList)) {
                return resultMap;
            }
            baseBean.writeLog("handleNowPushData mapList size:" + mapList.size());

            // 获取工号与id对应
            Map<String, String> ghAndIdMap = new HashMap<>();
            rs.execute("SELECT id, loginid FROM hrmresource WHERE loginid is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("loginid");
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                workcode = CommonUtil.removeLeadingZeros(workcode);
                if (StringUtils.isEmpty(workcode)) {
                    continue;
                }
                ghAndIdMap.put(workcode, id);
            }
            if (CollectionUtils.isEmpty(ghAndIdMap)) {
                return resultMap;
            }

            String fromType = "telpo";

//            String sql = "select * from HrmScheduleSign where signFrom = ?";
//            rs.executeQuery(sql, fromType);
//            Set<String> signSet = new HashSet<>();
//            while (rs.next()) {
//                String userId = rs.getString("userId");
//                String signDate = rs.getString("signDate");
//                String signTime = rs.getString("signTime");
//                String signFrom = rs.getString("signFrom");
//                if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(signDate) || StringUtils.isEmpty(signTime) || StringUtils.isEmpty(signFrom)) {
//                    continue;
//                }
//                if (!StringUtils.equals(signFrom, fromType)) {
//                    continue;
//                }
//                signSet.add(userId + "_" + signDate + "_" + signTime + "_" + signFrom);
//            }

            RecordSet rs1 = new RecordSet();

            Set<String> needFormatSet = new HashSet<>();
            List<List> insertList = new ArrayList<>();
            for (Map<String, Object> map : mapList) {
                Object pinObj = map.get("pin");
                Object timeObj = map.get("time");
                if (Objects.isNull(pinObj) || Objects.isNull(timeObj)) {
                    continue;
                }
                String pin = pinObj.toString();
                pin = CommonUtil.removeLeadingZeros(pin);
                if (StringUtils.isEmpty(pin)) {
                    continue;
                }
                String time = timeObj.toString();
                if (StringUtils.isEmpty(pin) || StringUtils.isEmpty(time)) {
                    continue;
                }
                if (pin.length() == 4 && pin.startsWith("9")) {
                    pin = "90" + pin;
                }
                String id = ghAndIdMap.get(pin);
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                baseBean.writeLog("handleNowPushData time:" + time + "、" + pin);
                String[] dt = time.split(" ");
                if (dt.length < 2) {
                    dt = time.split("=");
                    if (dt.length < 2) {
                        continue;
                    }
                }
                String rq = dt[0];
                String sj = dt[1];
                rs1.execute("select userId from HrmScheduleSign where signFrom = '" + fromType + "' and userId = " + id +
                        " and signDate = '" + rq + "' and signTime = '" + sj + "'");
                if (rs1.next()) {
                    String userIdTemp = rs1.getString("userId");
                    if (StringUtils.isNotEmpty(userIdTemp)) {
                        continue;
                    }
                }
//                String keyTemp = id + "_" + rq + "_" + sj + "_" + fromType;
//                if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
//                    continue;
//                }
                List list = new ArrayList();
                list.add(id);
                list.add("1");
                list.add(rq);
                list.add(sj);
                list.add("1");
                list.add(fromType);
                list.add(rq);
                Map<String, Object> mapT = new HashMap<>();
                mapT.put("deviceId", sn);
                list.add(JSONObject.toJSONString(mapT));
                insertList.add(list);
                needFormatSet.add(id + "_" + rq);
            }

            if (!CollectionUtils.isEmpty(insertList)) {
                String insertSql = "INSERT INTO HrmScheduleSign(userId, userType, signDate, signTime, isInCom, " +
                        "signFrom, belongdate, deviceinfo) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
                rs.executeBatchSql(insertSql, insertList);
            }
            baseBean.writeLog("handleNowPushData end.");
//            baseBean.writeLog("handleNowPushData needFormatSet:" + needFormatSet);
//            if (!CollectionUtils.isEmpty(needFormatSet)) {
//                for (String key : needFormatSet) {
//                    String yg = key.split("_")[0];
//                    String rq = key.split("_")[1];
//                    new KQFormatBiz().formatDate(yg, rq);
//                    SplitActionUtil.pushOverTimeTasksAll(rq, rq, "" + yg);
//                }
//            }
        } catch (Exception e) {
            baseBean.writeLog("handleNowPushData error:" + e);
        }

        return resultMap;
    }

    @Override
    public Map<String, Object> pushTaskResult(Map<String, Object> params) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", "00");
        baseBean.writeLog("pushTaskResult start.");
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        Object taskId = null;
        try {
            if (CollectionUtils.isEmpty(params)) {
                baseBean.writeLog("pushTaskResult params is null.");
                return resultMap;
            }
            baseBean.writeLog("pushTaskResult params is:" + JSONObject.toJSONString(params));
        } catch (Exception e) {
//            if (taskId != null) {
//                rs.executeUpdate("UPDATE uf_tssbjlglb SET sbclyc = ? WHERE rwid = ?", e.getMessage(), taskId);
//            }
            baseBean.writeLog("pushTaskResult error:" + e);
        }

        return resultMap;
    }

    @Override
    public Map<String, Object> getTbDoorData(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("getTbDoorData start:" + params);
        try {
            // 开始日期
            String ksrq = Util.null2String(params.get("ksrq"));
            // 结束日期
            String jsrq = Util.null2String(params.get("jsrq"));
            if (StringUtils.isEmpty(ksrq) || StringUtils.isEmpty(jsrq)) {
                baseBean.writeLog("getTbDoorData date error.");
                result.put("mes", "日期不能为空！");
                result.put("code", "200");
                return result;
            }
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate date1 = LocalDate.parse(ksrq, formatter);
            LocalDate date2 = LocalDate.parse(jsrq, formatter);

            if (date2.isBefore(date1)) {
                baseBean.writeLog("getTbDoorData date error.");
                result.put("mes", "结束日期不能在开始日期之前！");
                result.put("code", "200");
                return result;
            }

            // 员工
            String yg = Util.null2String(params.get("yg"));

//            ExecutorService executorService = Executors.newFixedThreadPool(1);
//            executorService.execute(new TBDataThread(yg, ksrq, jsrq));
//            // 关闭线程池
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//            }
            new Thread(() -> {
                RecordSet rs = new RecordSet();
                RecordSet rs1 = new RecordSet();
                try {
                    // 获取工号与id对应
                    Map<String, String> ghAndIdMap = new HashMap<>();
                    Map<String, String> idAndGhMap = new HashMap<>();
                    rs.execute("SELECT id, loginid FROM hrmresource WHERE loginid is not null");
                    while (rs.next()) {
                        String id = rs.getString("id");
                        String workcode = rs.getString("loginid");
                        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode)) {
                            continue;
                        }
                        workcode = CommonUtil.removeLeadingZeros(workcode);
                        if (StringUtils.isEmpty(workcode)) {
                            continue;
                        }
                        ghAndIdMap.put(workcode, id);
                        idAndGhMap.put(id, workcode);
                    }
                    if (CollectionUtils.isEmpty(idAndGhMap)) {
                        baseBean.writeLog("getTbDoorData idAndGhMap is null.");
//                    result.put("mes", "系统错误，请联系管理员！");
//                    result.put("code", "200");
//                    return result;
                    }

                    String modeId = rs.getPropValue("jzjg_zm_prop", "kqsjtbjl_mode_id");
                    String cusId = rs.getPropValue("jzjg_zm_prop", "kqsjtbjl_cus_id");
                    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
                    SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");

                    TelpoUtils telpoUtils = new TelpoUtils();

                    String startTime = ksrq + " 00:00:01";
                    String endTime = jsrq + " 23:59:59";

                    Map<String, Object> mapTemp = new HashMap<>();
                    if (StringUtils.isNotEmpty(yg)) {
                        String[] ygArr = yg.split(",");
                        List<String> ygList = new ArrayList<>();
                        for (String ygT : ygArr) {
                            String ghTemp = idAndGhMap.get(ygT);
                            if (StringUtils.isNotEmpty(ghTemp)) {
                                ygList.add(idAndGhMap.get(ygT));
                                if (ghTemp.length() == 6 && ghTemp.startsWith("90")) {
                                    ygList.add(ghTemp.substring(2, 6));
                                }
                            }
                        }
                        mapTemp.put("pin", ygList);
                    }
                    mapTemp.put("photo", 0);
                    mapTemp.put("start", startTime);
                    mapTemp.put("end", endTime);
                    String sbip = rs.getPropValue("jzjg_zm_prop", "tb_ip");
                    ;
                    // 获取天波考勤设备信息
                    rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE sblx = 0 AND sbip is not null AND sftskqsj = 0");
                    while (rs.next()) {
                        String id = rs.getString("id");
//                        String sbip = "192.168.1.43";
                        String sbxlh = rs.getString("sbxlh");
                        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(sbip) || StringUtils.isEmpty(sbxlh)) {
                            continue;
                        }
                        Map<String, Object> paramMap = new HashMap<>();
                        List<String> snList = new ArrayList<>();
                        snList.add(sbxlh);
                        paramMap.put("SN", snList);
                        long taskId = System.currentTimeMillis();
                        paramMap.put("taskId", taskId);
                        paramMap.put("type", "queryRecords");
                        paramMap.put("Data", mapTemp);
                        rs1.executeUpdate("INSERT INTO uf_kqsjtbjlb (sb, rwid, qqcs, formmodeid,MODEUUID,modedatacreater," +
                                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?)", id, taskId,
                                JSONObject.toJSONString(paramMap), modeId, UUID.randomUUID(), "1", "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                        telpoUtils.queryTelpoMj(sbip, paramMap, String.valueOf(taskId));

                        Thread.sleep(3000);
                    }
                } catch (Exception e) {
                    baseBean.writeLog("getTbDoorData thread error:" + e);
                    Thread.currentThread().interrupt(); // 处理中断
                }
            }).start();
        } catch (Exception e) {
            baseBean.writeLog("getTbDoorData error:" + e);
        }
        result.put("mes", "正在同步，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> getKsDoorData(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("getKsDoorData start:" + params);
        try {
            // 开始日期
            String ksrq = Util.null2String(params.get("ksrq"));
            // 结束日期
            String jsrq = Util.null2String(params.get("jsrq"));
            if (StringUtils.isEmpty(ksrq) || StringUtils.isEmpty(jsrq)) {
                baseBean.writeLog("getKsDoorData date error.");
                result.put("mes", "日期不能为空！");
                result.put("code", "200");
                return result;
            }
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate date1 = LocalDate.parse(ksrq, formatter);
            LocalDate date2 = LocalDate.parse(jsrq, formatter);

            if (date2.isBefore(date1)) {
                baseBean.writeLog("getKsDoorData date error.");
                result.put("mes", "结束日期不能在开始日期之前！");
                result.put("code", "200");
                return result;
            }

            // 员工
            String yg = Util.null2String(params.get("yg"));

            RecordSet rs = new RecordSet();
            // 获取工号与id对应
            Map<String, String> ghAndIdMap = new HashMap<>();
            Map<String, String> idAndGhMap = new HashMap<>();
            Map<String, String> idAndNameMap = new HashMap<>();
            rs.execute("SELECT id, loginid, lastname FROM hrmresource WHERE loginid is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("loginid");
                String lastname = rs.getString("lastname");
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode) || StringUtils.isEmpty(lastname)) {
                    continue;
                }
                idAndNameMap.put(id, lastname);
                workcode = CommonUtil.removeLeadingZeros(workcode);
                if (StringUtils.isEmpty(workcode)) {
                    continue;
                }
                ghAndIdMap.put(workcode, id);
                idAndGhMap.put(id, workcode);
            }
            if (CollectionUtils.isEmpty(ghAndIdMap)) {
                baseBean.writeLog("getKsDoorData ghAndIdMap is null.");
                result.put("mes", "系统错误，请联系管理员！");
                result.put("code", "200");
                return result;
            }

            // 获取旷视考勤设备ip
            Map<String, String> ipMap = new HashMap<>();
            Set<String> ipSet = new HashSet<>();
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE sblx = 1 AND sbip is not null AND sftskqsj = 0");
            while (rs.next()) {
                String sbip = rs.getString("sbip");
                String sbxlh = rs.getString("sbxlh");
                if (StringUtils.isNotEmpty(sbip)) {
                    ipSet.add(sbip);
                    ipMap.put(sbip, sbxlh);
                }
            }
            if (CollectionUtils.isEmpty(ipSet)) {
                baseBean.writeLog("getKsDoorData ipSet is null.");
                result.put("mes", "旷视设备ip为空！");
                result.put("code", "200");
                return result;
            }

            String startTime = ksrq + "T00:00:01+08:00";
            String endTime = jsrq + "T23:59:59+08:00";

            String fromType = "megvii";

            String sql = "select * from HrmScheduleSign where signFrom = ? AND belongdate between '" + ksrq + "' and '" + jsrq + "'";
            rs.executeQuery(sql, fromType);
            Set<String> signSet = new HashSet<>();
            while (rs.next()) {
                String userId = rs.getString("userId");
                String signDate = rs.getString("signDate");
                String signTime = rs.getString("signTime");
                String signFrom = rs.getString("signFrom");
                if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(signDate) || StringUtils.isEmpty(signTime) || StringUtils.isEmpty(signFrom)) {
                    continue;
                }
                if (!StringUtils.equals(signFrom, fromType)) {
                    continue;
                }
                signSet.add(userId + "_" + signDate + "_" + signTime + "_" + signFrom);
            }

            KsUtils ksUtils = new KsUtils();
            for (String ip : ipSet) {
                try {
                    // 登陆鉴权挑战
                    String paramStr = ksUtils.loginChallenge("admin", ip);
                    Gson gson = new Gson();
                    Type type = new TypeToken<Map<String, Object>>() {
                    }.getType();
                    Map<String, Object> mapC = gson.fromJson(paramStr, type);

                    Object session_id = mapC.get("session_id");
                    Object challenge = mapC.get("challenge");
                    Object salt = mapC.get("salt");
                    if (Objects.isNull(session_id) || Objects.isNull(challenge) || Objects.isNull(salt)) {
                        baseBean.writeLog("getKsDoorData login challenge failed.");
                        result.put("mes", "系统错误，请联系管理员！");
                        result.put("code", "200");
                        return result;
                    }
                    // 设备登陆
                    String loginRes = ksUtils.login(session_id.toString(), challenge.toString(), salt.toString(), ip);
                    Map<String, Object> mapIn = gson.fromJson(loginRes, type);
                    Object sessionIdNew = mapIn.get("session_id");
                    Type typeMapList = new TypeToken<List<Map<String, String>>>() {
                    }.getType();

                    String sbxlh = ipMap.get(ip);
                    Map<String, Object> mapT = new HashMap<>();
                    mapT.put("deviceId", sbxlh);

                    Set<String> needFormatSet = new HashSet<>();
                    List<List> insertList = new ArrayList<>();

                    if (StringUtils.isNotEmpty(yg)) {
                        String[] ygArr = yg.split(",");
                        for (String ygId : ygArr) {
//                        String workcodeA = idAndGhMap.get(ygId);
//                        if (StringUtils.isEmpty(workcodeA)) {
//                            continue;
//                        }
//                        workcodeA = CommonUtil.removeLeadingZeros(workcodeA);
//                        if (StringUtils.isEmpty(workcodeA)) {
//                            continue;
//                        }
                            String ygxm = idAndNameMap.get(ygId);
                            if (StringUtils.isEmpty(ygxm)) {
                                continue;
                            }
                            Map<String, Object> paramMap = new HashMap<>();
                            int limit = 2000;
                            int offset = 0;
                            paramMap.put("limit", limit);
                            paramMap.put("sort", "asc");
                            paramMap.put("begin_time", startTime);
                            paramMap.put("end_time", endTime);
//                        paramMap.put("query_person_idx", workcodeA);
                            paramMap.put("query_string", ygxm);

                            boolean isGoing = true;
                            while (isGoing) {
                                int offsetInt = offset * limit;
                                paramMap.put("offset", offsetInt);
                                String doorStr = ksUtils.queryMj(sessionIdNew.toString(), paramMap, ip);
                                if (StringUtils.isEmpty(doorStr)) {
                                    isGoing = false;
                                    break;
                                }
                                Map<String, Object> doorMap = gson.fromJson(doorStr, type);
                                Object paging = doorMap.get("paging");
                                if (Objects.isNull(paging)) {
                                    isGoing = false;
                                    break;
                                }
                                Map<String, Object> pageMap = gson.fromJson(paging.toString(), type);
                                Object total = pageMap.get("total");
                                if (Objects.isNull(total)) {
                                    isGoing = false;
                                    break;
                                }
                                if (new BigDecimal(String.valueOf(offsetInt)).compareTo(new BigDecimal(total.toString())) < 0) {
                                    offset = offset + 1;
                                } else {
                                    isGoing = false;
                                }
                                Object data = doorMap.get("data");
                                if (Objects.isNull(data)) {
                                    isGoing = false;
                                    break;
                                }
                                List<Map<String, String>> mapList = (List<Map<String, String>>) data;
                                for (Map<String, String> map : mapList) {
                                    String workcode = map.get("person_code");
                                    String timestamp = map.get("timestamp");
                                    if (StringUtils.isEmpty(timestamp) || StringUtils.isEmpty(workcode)) {
                                        continue;
                                    }
                                    if (workcode.length() == 4 && workcode.startsWith("9")) {
                                        workcode = "90" + workcode;
                                    }
                                    workcode = CommonUtil.removeLeadingZeros(workcode);
                                    String time = CommonUtil.getDateStrFromIso8601(timestamp);
                                    String id = ghAndIdMap.get(workcode);
                                    if (StringUtils.isEmpty(id)) {
                                        continue;
                                    }
                                    String[] dt = time.split(" ");
                                    String rq = dt[0];
                                    String sj = dt[1];

                                    String keyTemp = id + "_" + rq + "_" + sj + "_" + fromType;
                                    if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
                                        continue;
                                    }

                                    List list = new ArrayList();
                                    list.add(id);
                                    list.add("1");
                                    list.add(rq);
                                    list.add(sj);
                                    list.add("1");
                                    list.add(fromType);
                                    list.add(rq);
                                    list.add(JSONObject.toJSONString(mapT));
                                    insertList.add(list);
                                    needFormatSet.add(id + "_" + rq);
                                }
                            }
                        }
                    } else {
                        Map<String, Object> paramMap = new HashMap<>();
                        int limit = 2000;
                        int offset = 0;
                        paramMap.put("limit", limit);
                        paramMap.put("sort", "asc");
                        paramMap.put("begin_time", startTime);
                        paramMap.put("end_time", endTime);

                        boolean isGoing = true;
                        while (isGoing) {
                            int offsetInt = offset * limit;
                            paramMap.put("offset", offsetInt);
                            String doorStr = ksUtils.queryMj(sessionIdNew.toString(), paramMap, ip);
                            if (StringUtils.isEmpty(doorStr)) {
                                isGoing = false;
                                break;
                            }
                            Map<String, Object> doorMap = gson.fromJson(doorStr, type);
                            Object paging = doorMap.get("paging");
                            if (Objects.isNull(paging)) {
                                isGoing = false;
                                break;
                            }
                            Map<String, Object> pageMap = gson.fromJson(paging.toString(), type);
                            Object total = pageMap.get("total");
                            if (Objects.isNull(total)) {
                                isGoing = false;
                                break;
                            }
                            if (new BigDecimal(String.valueOf(offsetInt)).compareTo(new BigDecimal(total.toString())) < 0) {
                                offset = offset + 1;
                            } else {
                                isGoing = false;
                            }
                            Object data = doorMap.get("data");
                            if (Objects.isNull(data)) {
                                isGoing = false;
                                break;
                            }
                            List<Map<String, String>> mapList = (List<Map<String, String>>) data;
                            for (Map<String, String> map : mapList) {
                                String workcode = map.get("person_code");
                                String timestamp = map.get("timestamp");
                                if (StringUtils.isEmpty(timestamp) || StringUtils.isEmpty(workcode)) {
                                    continue;
                                }
                                if (workcode.length() == 4 && workcode.startsWith("9")) {
                                    workcode = "90" + workcode;
                                }
                                workcode = CommonUtil.removeLeadingZeros(workcode);
                                String time = CommonUtil.getDateStrFromIso8601(timestamp);
                                String id = ghAndIdMap.get(workcode);
                                if (StringUtils.isEmpty(id)) {
                                    continue;
                                }
                                String[] dt = time.split(" ");
                                String rq = dt[0];
                                String sj = dt[1];

                                String keyTemp = id + "_" + rq + "_" + sj + "_" + fromType;
                                if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
                                    continue;
                                }

                                List list = new ArrayList();
                                list.add(id);
                                list.add("1");
                                list.add(rq);
                                list.add(sj);
                                list.add("1");
                                list.add(fromType);
                                list.add(rq);
                                list.add(JSONObject.toJSONString(mapT));
                                insertList.add(list);
                                needFormatSet.add(id + "_" + rq);
                            }
                        }
                    }

                    if (!CollectionUtils.isEmpty(insertList)) {
                        String insertSql = "INSERT INTO HrmScheduleSign(userId, userType, signDate, signTime, isInCom, " +
                                "signFrom, belongdate, deviceinfo) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
                        rs.executeBatchSql(insertSql, insertList);
                    }

//                if (!CollectionUtils.isEmpty(needFormatSet)) {
//                    for (String key : needFormatSet) {
//                        String ryId = key.split("_")[0];
//                        String rq = key.split("_")[1];
//                        new KQFormatBiz().formatDate(ryId, rq);
//                        SplitActionUtil.pushOverTimeTasksAll(rq, rq, "" + ryId);
//                    }
//                }

                    // 设备登出
                    ksUtils.logout(session_id.toString(), ip);
                } catch (Exception e) {
                    baseBean.writeLog("getKsDoorData single error:" + ip + "、" + e);
                }
            }

            // 中间库方案(弃用)
            /*Set<String> needFormatSet = new HashSet<>();
            List<List> insertList = new ArrayList<>();
            Gson gson = new Gson();
            Type typeMap = new TypeToken<Map<String, String>>() {
            }.getType();
            List<String> idSet = new ArrayList<>();
            String jsrqStr = jsrq + " 23:59:59";
            rs.executeSqlWithDataSource("select * from AttendanceData where (FLAG = 0 or flag is null ) and TIMESTAMP >= '"
                    + ksrq + "' and TIMESTAMP <= '" + jsrqStr + "'", "KSKQ");
            while (rs.next()) {
                String dataId = rs.getString("id");
                String data = rs.getString("data");
                String PERSON_CODE = rs.getString("PERSON_CODE");
                if (StringUtils.isEmpty(dataId) || StringUtils.isEmpty(data) || StringUtils.isEmpty(PERSON_CODE)) {
                    continue;
                }
                Map<String, String> map = gson.fromJson(data, typeMap);
                String workcode = map.get("person_code");
                String timestamp = map.get("timestamp");
                if (StringUtils.isEmpty(timestamp) || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                if (workcode.length() == 4 && workcode.startsWith("9")) {
                    workcode = "90" + workcode;
                }
                workcode = CommonUtil.removeLeadingZeros(workcode);
                String time = CommonUtil.getDateStrFromIso8601(timestamp);
                String id = ghAndIdMap.get(workcode);
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                if (StringUtils.isNotEmpty(yg)) {
                    List<String> ygArr = Arrays.asList(yg.split(","));
                    if (!ygArr.contains(id)) {
                        continue;
                    }
                }
                String[] dt = time.split(" ");
                String rq = dt[0];
                String sj = dt[1];
                String keyTemp = id + "_" + rq + "_" + sj + "_" + fromType;
                if ((!CollectionUtils.isEmpty(signSet)) && signSet.contains(keyTemp)) {
                    continue;
                }
                List list = new ArrayList();
                list.add(id);
                list.add("1");
                list.add(rq);
                list.add(sj);
                list.add("1");
                list.add(fromType);
                list.add(rq);
                insertList.add(list);
                needFormatSet.add(id + "_" + rq);
                idSet.add(dataId);
            }

            if (!CollectionUtils.isEmpty(insertList)) {
                baseBean.writeLog("getKsDoorData insertList size is:" + insertList.size());
                String insertSql = "INSERT INTO HrmScheduleSign(userId, userType, signDate, signTime, isInCom, " +
                        "signFrom, belongdate) VALUES (?, ?, ?, ?, ?, ?, ?)";
                rs.executeBatchSql(insertSql, insertList);
            }

            if (!CollectionUtils.isEmpty(idSet)) {
                baseBean.writeLog("getKsDoorData idSet size is:" + idSet.size());
                int batchSize = 100; // 每个小集合的大小
                int size = idSet.size(); // 原始集合的大小
                int numberOfBatches = (int) Math.ceil((double) size / batchSize); // 划分的小集合数量
                List<List<String>> dividedLists = new ArrayList<>(); // 存储划分后的小集合

                for (int i = 0; i < numberOfBatches; i++) {
                    int fromIndex = i * batchSize;
                    int toIndex = Math.min((i + 1) * batchSize, size);
                    List<String> batch = idSet.subList(fromIndex, toIndex);
                    dividedLists.add(batch);
                }

                for (List<String> batch : dividedLists) {
                    String ids = String.join(",", batch);
                    rs.executeSqlWithDataSource("update AttendanceData set flag = 1 WHERE id in (" + ids + ")", "KSKQ");
                }
            }

            if (!CollectionUtils.isEmpty(needFormatSet)) {
                for (String key : needFormatSet) {
                    String ygT = key.split("_")[0];
                    String rq = key.split("_")[1];
                    new KQFormatBiz().formatDate(ygT, rq);
                    SplitActionUtil.pushOverTimeTasksAll(rq, rq, "" + ygT);
                }
            }*/
            baseBean.writeLog("getKsDoorData end.");
        } catch (Exception e) {
            baseBean.writeLog("getKsDoorData error:" + e);
        }
        result.put("mes", "正在同步，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public void pushHrmToKs(String ip, Map<String, Object> params, String dataId) {
        baseBean.writeLog("pushHrmToKs start:" + params);
        RecordSet rs = new RecordSet();
        try {
            KsUtils ksUtils = new KsUtils();
            Map<String, Object> ksParams = new HashMap<>();
            Map<String, Object> ksParams_pk = new HashMap<>();
            // 人员类型  staff – 普通人员，visitor – 访客，blacklist – 黑名单
            ksParams.put("recognition_type", "staff");
            ksParams_pk.put("recognition_type", "staff");
            // 人员id
            ksParams.put("id", params.get("id"));
            ksParams_pk.put("id", params.get("id"));
            // 是否启用管理员权限
            ksParams.put("is_admin", "false");
            ksParams_pk.put("is_admin", "false");
            // 人员姓名
            ksParams.put("person_name", params.get("person_name"));
            ksParams_pk.put("person_name", params.get("person_name"));
            // 人员编号
            ksParams.put("person_code", params.get("person_code"));
            ksParams_pk.put("person_code", params.get("person_code"));

            // 人脸照片 Base64编码的照片数据
            Object imageFileId = params.get("rytx");
            if (Objects.nonNull(imageFileId)) {
                String imageBase64 = CommonUtil.imageBase64(Integer.parseInt(imageFileId.toString()));
                List<Map<String, Object>> mapList = new ArrayList<>();
                Map<String, Object> mapTemp = new HashMap<>();
                mapTemp.put("idx", 0);
                mapTemp.put("data", imageBase64);
                mapList.add(mapTemp);
                ksParams.put("face_list", mapList);
                ksParams_pk.put("face_list", "YES");
            }

            // 登陆鉴权挑战
            String paramStr = ksUtils.loginChallenge("admin", ip);
            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            Map<String, Object> mapC = gson.fromJson(paramStr, type);

            Object session_id = mapC.get("session_id");
            Object challenge = mapC.get("challenge");
            Object salt = mapC.get("salt");
            if (Objects.isNull(session_id) || Objects.isNull(challenge) || Objects.isNull(salt)) {
                baseBean.writeLog("pushHrmToKs login challenge failed.");
                return;
            }
            // 设备登陆
            String loginRes = ksUtils.login(session_id.toString(), challenge.toString(), salt.toString(), ip);
            Map<String, Object> mapIn = gson.fromJson(loginRes, type);
            Object sessionIdNew = mapIn.get("session_id");

            // 身份证号码，需要aes加密
//            Object id_number = params.get("id_number");
//            if (Objects.nonNull(id_number)) {
//                String encryptedText = CommonUtil.encrypt(id_number.toString(), sessionIdNew.toString());
//                ksParams.put("id_number", encryptedText);
//            }

            List<String> groupList = new ArrayList<>();
            groupList.add("1");
            ksParams.put("group_list", groupList);
            ksParams_pk.put("group_list", groupList);

            baseBean.writeLog("pushHrmToKs ksParams is:" + JSONObject.toJSONString(ksParams_pk));
            String createRes = ksUtils.createHrm(sessionIdNew.toString(), ksParams, ip);
            rs.executeUpdate("UPDATE uf_tssbjlglb SET xycs = ?, zt = 2 WHERE id = ?", createRes, dataId);

            // 设备登出
            ksUtils.logout(session_id.toString(), ip);
        } catch (Exception e) {
            rs.executeUpdate("UPDATE uf_tssbjlglb SET ycyy = ?, zt = 1 WHERE id = ?", e.getMessage(), dataId);
            baseBean.writeLog("pushHrmToKs error:" + e);
        }
        baseBean.writeLog("pushHrmToKs end.");
    }

    public void updateHrmByIdKs(String ip, Map<String, Object> params, String dataId) {
        baseBean.writeLog("updateHrmByIdKs start:" + params);
        RecordSet rs = new RecordSet();
        try {
            KsUtils ksUtils = new KsUtils();
            Map<String, Object> ksParams = new HashMap<>();
            Map<String, Object> ksParams_pk = new HashMap<>();
            Object ryId = params.get("id");
            // 人员类型  staff – 普通人员，visitor – 访客，blacklist – 黑名单
            ksParams.put("recognition_type", "staff");
            ksParams_pk.put("recognition_type", "staff");
            // 人员id
            ksParams.put("id", ryId);
            ksParams_pk.put("id", ryId);
            // 是否启用管理员权限
            ksParams.put("is_admin", "false");
            ksParams_pk.put("is_admin", "false");
            // 人员姓名
            ksParams.put("person_name", params.get("person_name"));
            ksParams_pk.put("person_name", params.get("person_name"));
            // 人员编号
            ksParams.put("person_code", params.get("person_code"));
            ksParams_pk.put("person_code", params.get("person_code"));

            // 人脸照片 Base64编码的照片数据
            Object imageFileId = params.get("rytx");
            if (Objects.nonNull(imageFileId)) {
                String imageBase64 = CommonUtil.imageBase64(Integer.parseInt(imageFileId.toString()));
                List<Map<String, Object>> mapList = new ArrayList<>();
                Map<String, Object> mapTemp = new HashMap<>();
                mapTemp.put("idx", 0);
                mapTemp.put("data", imageBase64);
                mapList.add(mapTemp);
                ksParams.put("face_list", mapList);
                ksParams_pk.put("face_list", "YES");
            }

            // 登陆鉴权挑战
            String paramStr = ksUtils.loginChallenge("admin", ip);
            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            Map<String, Object> mapC = gson.fromJson(paramStr, type);

            Object session_id = mapC.get("session_id");
            Object challenge = mapC.get("challenge");
            Object salt = mapC.get("salt");
            if (Objects.isNull(session_id) || Objects.isNull(challenge) || Objects.isNull(salt)) {
                baseBean.writeLog("updateHrmByIdKs login challenge failed.");
                return;
            }
            // 设备登陆
            String loginRes = ksUtils.login(session_id.toString(), challenge.toString(), salt.toString(), ip);
            Map<String, Object> mapIn = gson.fromJson(loginRes, type);
            Object sessionIdNew = mapIn.get("session_id");

            List<String> groupList = new ArrayList<>();
            groupList.add("1");
            ksParams.put("group_list", groupList);
            ksParams_pk.put("group_list", groupList);

            baseBean.writeLog("updateHrmByIdKs ksParams is:" + JSONObject.toJSONString(ksParams_pk));
            String createRes = ksUtils.updateHrm(sessionIdNew.toString(), ksParams, ryId.toString(), ip);
            rs.executeUpdate("UPDATE uf_tssbjlglb SET xycs = ?, zt = 2 WHERE id = ?", createRes, dataId);

        } catch (Exception e) {
            rs.executeUpdate("UPDATE uf_tssbjlglb SET ycyy = ?, zt = 1 WHERE id = ?", e.getMessage(), dataId);
            baseBean.writeLog("updateHrmByIdKs error:" + e);
        }
        baseBean.writeLog("updateHrmByIdKs end.");
    }

    @Override
    public String queryHrmById(String ip, String yggh, String dataId) {
        baseBean.writeLog("queryHrmById start:" + yggh);
        RecordSet rs = new RecordSet();
        String result = null;
        try {
            KsUtils ksUtils = new KsUtils();
            // 人员id
            if (StringUtils.isEmpty(yggh)) {
                baseBean.writeLog("queryHrmById yggh is null.");
                return result;
            }

            // 登陆鉴权挑战
            String paramStr = ksUtils.loginChallenge("admin", ip);
            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            Map<String, Object> mapC = gson.fromJson(paramStr, type);

            Object session_id = mapC.get("session_id");
            Object challenge = mapC.get("challenge");
            Object salt = mapC.get("salt");
            if (Objects.isNull(session_id) || Objects.isNull(challenge) || Objects.isNull(salt)) {
                baseBean.writeLog("queryHrmById login challenge failed.");
                return result;
            }
            // 设备登陆
            String loginRes = ksUtils.login(session_id.toString(), challenge.toString(), salt.toString(), ip);
            Map<String, Object> mapIn = gson.fromJson(loginRes, type);
            Object sessionIdNew = mapIn.get("session_id");

            result = ksUtils.queryHrmById(sessionIdNew.toString(), ip, yggh);
//            rs.executeUpdate("UPDATE uf_tssbjlglb SET xycs = ? WHERE id = ?", createRes, dataId);

            // 设备登出
            ksUtils.logout(session_id.toString(), ip);
        } catch (Exception e) {
//            rs.executeUpdate("UPDATE uf_tssbjlglb SET ycyy = ?, zt = 1 WHERE id = ?", e.getMessage(), dataId);
            baseBean.writeLog("queryHrmById error:" + e);
        }
        baseBean.writeLog("queryHrmById end.");
        return result;
    }

    @Override
    public void delHrmInKs(String ip, Map<String, Object> params, String dataId) {
        baseBean.writeLog("delHrmInKs start:" + params);
        RecordSet rs = new RecordSet();
        try {
            KsUtils ksUtils = new KsUtils();
            // 人员id
            Object ygghObj = params.get("id");
            if (Objects.isNull(ygghObj) || ygghObj == "") {
                baseBean.writeLog("delHrmInKs ygghObj is null.");
                return;
            }

            String yggh = CommonUtil.removeLeadingZeros(ygghObj.toString());
            if (StringUtils.isEmpty(yggh)) {
                baseBean.writeLog("delHrmInKs yggh is null.");
                return;
            }

            // 登陆鉴权挑战
            String paramStr = ksUtils.loginChallenge("admin", ip);
            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            Map<String, Object> mapC = gson.fromJson(paramStr, type);

            Object session_id = mapC.get("session_id");
            Object challenge = mapC.get("challenge");
            Object salt = mapC.get("salt");
            if (Objects.isNull(session_id) || Objects.isNull(challenge) || Objects.isNull(salt)) {
                baseBean.writeLog("delHrmInKs login challenge failed.");
                return;
            }
            // 设备登陆
            String loginRes = ksUtils.login(session_id.toString(), challenge.toString(), salt.toString(), ip);
            Map<String, Object> mapIn = gson.fromJson(loginRes, type);
            Object sessionIdNew = mapIn.get("session_id");

            String createRes = ksUtils.delHrm(sessionIdNew.toString(), yggh, ip);
            rs.executeUpdate("UPDATE uf_tssbjlglb SET xycs = ? WHERE id = ?", createRes, dataId);

        } catch (Exception e) {
            rs.executeUpdate("UPDATE uf_tssbjlglb SET ycyy = ?, zt = 1 WHERE id = ?", e.getMessage(), dataId);
            baseBean.writeLog("delHrmInKs error:" + e);
        }
        baseBean.writeLog("delHrmInKs end.");
    }

    @Override
    public void pushHrmToTb(String ip, Map<String, Object> params, String dataId) {
        baseBean.writeLog("pushHrmToTb start:" + params);
        RecordSet rs = new RecordSet();
        try {
            String url = "http://" + ip + ":1820/Face/downUser";
            String result = HttpRequest.post(url)
                    .header(Header.CONTENT_TYPE, "application/json")
                    .body(JSONObject.toJSONString(params))
                    .timeout(20000)
                    .execute().body();
            if (StringUtils.isEmpty(result)) {
                baseBean.writeLog("pushHrmToTb result is null.");
                rs.executeUpdate("UPDATE uf_tssbjlglb SET zt = 1 WHERE id = ?", dataId);
                return;
            }
            rs.executeUpdate("UPDATE uf_tssbjlglb SET xycs = ? WHERE id = ?", result, dataId);
            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            Map<String, Object> resultMap = gson.fromJson(result, type);
            Object errCode = resultMap.get("errCode");
            if (Objects.nonNull(errCode) && StringUtils.equals(errCode.toString(), "00")) {
                rs.executeUpdate("UPDATE uf_tssbjlglb SET zt = 2 WHERE id = ?", dataId);
            }
        } catch (Exception e) {
            rs.executeUpdate("UPDATE uf_tssbjlglb SET ycyy = ?, zt = 1 WHERE id = ?", e.getMessage(), dataId);
            baseBean.writeLog("pushHrmToKs error:" + e);
        }
        baseBean.writeLog("pushHrmToKs end.");
    }

    @Override
    public void delHrmInTb(String ip, Map<String, Object> params, String dataId) {
        baseBean.writeLog("delHrmInTb start:" + params);
        RecordSet rs = new RecordSet();
        try {
            String url = "http://" + ip + ":1820/Face/delUser";
            String result = HttpRequest.post(url)
                    .header(Header.CONTENT_TYPE, "application/json")
                    .body(JSONObject.toJSONString(params))
                    .timeout(20000)
                    .execute().body();
            if (StringUtils.isEmpty(result)) {
                baseBean.writeLog("delHrmInTb result is null.");
                rs.executeUpdate("UPDATE uf_tssbjlglb SET zt = 1 WHERE id = ?", dataId);
                return;
            }
            rs.executeUpdate("UPDATE uf_tssbjlglb SET xycs = ? WHERE id = ?", result, dataId);
            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            Map<String, Object> resultMap = gson.fromJson(result, type);
            Object errCode = resultMap.get("errCode");
            if (Objects.nonNull(errCode) && StringUtils.equals(errCode.toString(), "00")) {
                rs.executeUpdate("UPDATE uf_tssbjlglb SET zt = 2 WHERE id = ?", dataId);
            }
        } catch (Exception e) {
            rs.executeUpdate("UPDATE uf_tssbjlglb SET ycyy = ?, zt = 1 WHERE id = ?", e.getMessage(), dataId);
            baseBean.writeLog("delHrmInTb error:" + e);
        }
        baseBean.writeLog("delHrmInTb end.");
    }

    @Override
    public Map<String, Object> pushAgain(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("pushAgain start:" + params);
        try {
            String id = Util.null2String(params.get("id"));
            if (StringUtils.isEmpty(id)) {
                baseBean.writeLog("pushAgain id is null.");
                result.put("code", "400");
                result.put("msg", "id is null.");
                return result;
            }
            RecordSet rs = new RecordSet();
            rs.execute("SELECT a.*,b.sblx,b.sbxlh,b.sbip FROM uf_tssbjlglb a LEFT JOIN uf_kqsbdzgxgljmb b ON a.sb = b.id WHERE id = " + id);
            while (rs.next()) {
                String dataId = rs.getString("id");
                String qqcsjmq = rs.getString("qqcsjmq");
                String tslx = rs.getString("tslx");
                String sblx = rs.getString("sblx");
                String sbxlh = rs.getString("sbxlh");
                String sbip = rs.getString("sbip");

                if (StringUtils.isEmpty(qqcsjmq)) {
                    continue;
                }
                if (StringUtils.equals(tslx, "0")) {
                    if (StringUtils.equals(sblx, "0")) {

                    }
                }
                if (StringUtils.equals(tslx, "1")) {

                }
                if (StringUtils.equals(tslx, "2")) {

                }
            }
        } catch (Exception e) {
            baseBean.writeLog("pushAgain error:" + e);
        }
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> pushHrmToDevice(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("pushHrmToDevice start:" + params);
        try {
            String id = Util.null2String(params.get("id"));
            if (StringUtils.isEmpty(id)) {
                baseBean.writeLog("pushHrmToDevice id is null.");
                result.put("code", "400");
                result.put("msg", "id is null.");
                return result;
            }
            Map<String, Set<String>> setMap = new HashMap<>();
            Map<String, String> ipIdMap = new HashMap<>();
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE sbip is not null");
            while (rs.next()) {
                String idT = rs.getString("id");
                String sbip = rs.getString("sbip");
                String sblx = rs.getString("sblx");
                String sbxlh = rs.getString("sbxlh");
                String sbgzbm = rs.getString("sbgzbm");
                if (StringUtils.isEmpty(sbip) || StringUtils.isEmpty(sblx) || StringUtils.isEmpty(sbgzbm) || StringUtils.isEmpty(id)) {
                    continue;
                }
                if (StringUtils.isEmpty(sbxlh)) {
                    sbxlh = "0";
                }
                ipIdMap.put(sbip, idT);
                String[] bmArr = sbgzbm.split(",");
                for (String bm : bmArr) {
                    Set<String> ipSet = new HashSet<>();
                    if ((!CollectionUtils.isEmpty(setMap)) && setMap.containsKey(bm)) {
                        ipSet = setMap.get(bm);
                    }
                    ipSet.add(sbip + "_" + sblx + "_" + sbxlh);
                    setMap.put(bm, ipSet);
                }
            }

            if (CollectionUtils.isEmpty(setMap)) {
                baseBean.writeLog("pushHrmToDevice setMap is null.");
                result.put("code", "400");
                result.put("msg", "device info id null.");
                return result;
            }

            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            String modeId = rs.getPropValue("jzjg_zm_prop", "tssbjl_mode_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            String tbsbip = rs.getPropValue("jzjg_zm_prop", "tb_ip");

            rs.execute("SELECT loginid, lastname, departmentid, resourceimageid FROM HrmResource WHERE id in (" + id + ")");
            while (rs.next()) {
                String loginid = rs.getString("loginid");
                String lastname = rs.getString("lastname");
                String departmentid = rs.getString("departmentid");
                if (StringUtils.isEmpty(loginid) || StringUtils.isEmpty(lastname) || StringUtils.isEmpty(departmentid)) {
                    continue;
                }
                String sfzhm = null;
                Set<String> ipSet = setMap.get(departmentid);
                if (CollectionUtils.isEmpty(ipSet)) {
                    continue;
                }
                loginid = CommonUtil.removeLeadingZeros(loginid);
                if (StringUtils.isEmpty(loginid)) {
                    continue;
                }
                Map<String, Object> ksParamMap = new HashMap<>();
                String rytx = rs.getString("resourceimageid");
                for (String ipInfo : ipSet) {
                    String sbip = ipInfo.split("_")[0];
                    String sblx = ipInfo.split("_")[1];
                    String sbsn = ipInfo.split("_")[2];

                    String kqjId = ipIdMap.get(sbip);
                    // 如果是旷视，则先查询是否存在，存在则修改，不存在则新增
                    if (new BigDecimal(sblx).compareTo(new BigDecimal("1")) == 0) {
                        ksParamMap = new HashMap<>();
                        // 人员id
                        ksParamMap.put("id", loginid);
                        // 人员姓名
                        ksParamMap.put("person_name", lastname);
                        // 人员编号
                        ksParamMap.put("person_code", loginid);
                        // 身份证号码，需要aes加密
                        if (StringUtils.isNotEmpty(sfzhm)) {
                            ksParamMap.put("id_number", sfzhm);
                        }
                        // 人员头像
                        if (StringUtils.isNotEmpty(rytx)) {
                            ksParamMap.put("rytx", rytx);
                        }

                        boolean isExist = false;
                        String queryRes = queryHrmById(sbip, loginid, null);
                        try {
                            Map<String, Object> queryMap = gson.fromJson(queryRes, type);
                            if (queryMap.get("id") != null && StringUtils.equals(queryMap.get("id").toString(), loginid)) {
                                isExist = true;
                            }
                        } catch (Exception e) {
                        }
                        if (isExist) {
                            baseBean.writeLog("pushHrmToDevice isExist:" + isExist + "、" + ksParamMap);
                            String uuid = UUID.randomUUID() + "-" + loginid;
                            rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                            "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?)",
                                    kqjId, JSONObject.toJSONString(ksParamMap), "3", "3", modeId, uuid, "1",
                                    "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                            continue;
//                            String dataId = null;
//                            rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
//                            if (rs1.next()) {
//                                dataId = rs1.getString("id");
//                            }
//                            updateHrmByIdKs(sbip, ksParamMap, dataId);
                        } else {
                            String uuid = UUID.randomUUID() + "-" + loginid;
                            rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                            "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?)",
                                    kqjId, JSONObject.toJSONString(ksParamMap), "0", "3", modeId, uuid, "1",
                                    "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                            String dataId = null;
                            rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                            if (rs1.next()) {
                                dataId = rs1.getString("id");
                            }
                            pushHrmToKs(sbip, ksParamMap, dataId);
                        }
                    }

                    if (new BigDecimal(sblx).compareTo(new BigDecimal("0")) == 0) {
                        sbip = tbsbip;
                        Map<String, Object> tbParamMap = new HashMap<>();
                        tbParamMap.put("SN", sbsn);
                        long taskId = System.currentTimeMillis();
                        tbParamMap.put("taskId", taskId);
                        Map<String, Object> tbParamMap_copy = new HashMap<>();
                        tbParamMap_copy.put("SN", sbsn);
                        tbParamMap_copy.put("taskId", taskId);
                        List<Map<String, Object>> mapList = new ArrayList<>();
                        List<Map<String, Object>> mapList_copy = new ArrayList<>();
                        Map<String, Object> mapTemp = new HashMap<>();
                        mapTemp.put("pin", loginid);
                        mapTemp.put("name", lastname);
                        mapTemp.put("userType", 0);
                        Map<String, Object> mapTemp_copy = new HashMap<>();
                        mapTemp_copy.put("pin", loginid);
                        mapTemp_copy.put("name", lastname);
                        mapTemp_copy.put("userType", 0);

                        if (StringUtils.isNotEmpty(rytx)) {
                            String imageBase64 = CommonUtil.imageBase64(Integer.parseInt(rytx));
                            mapTemp.put("photo", imageBase64);
                        }
                        mapList.add(mapTemp);
                        mapList_copy.add(mapTemp_copy);
                        tbParamMap.put("Data", mapList);
                        tbParamMap_copy.put("Data", mapList_copy);

                        String uuid = UUID.randomUUID() + "-" + loginid;
                        rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?)",
                                kqjId, JSONObject.toJSONString(tbParamMap_copy), "0", "3", modeId, uuid, "1",
                                "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                        String dataId = null;
                        rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                        if (rs1.next()) {
                            dataId = rs1.getString("id");
                        }
                        pushHrmToTb(sbip, tbParamMap, dataId);
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog("pushHrmToDevice error:" + e);
        }
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> pushHrmToAppointDevice(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("pushHrmToAppointDevice start:" + params);
        try {
            String id = Util.null2String(params.get("ryId"));
            String sbId = Util.null2String(params.get("sbId"));
            if (StringUtils.isEmpty(id) || StringUtils.isEmpty(sbId)) {
                baseBean.writeLog("pushHrmToAppointDevice params is null.");
                result.put("code", "400");
                result.put("msg", "params is null.");
                return result;
            }
            List<Map<String, String>> sbMapList = new ArrayList<>();
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE id in (" + sbId + ")");
            while (rs.next()) {
                String idT = rs.getString("id");
                String sbip = rs.getString("sbip");
                String sblx = rs.getString("sblx");
                String sbxlh = rs.getString("sbxlh");
                if (StringUtils.isEmpty(sbip) || StringUtils.isEmpty(sblx) || StringUtils.isEmpty(id)) {
                    continue;
                }
                if (StringUtils.isEmpty(sbxlh)) {
                    sbxlh = "0";
                }
                Map<String, String> sbInfoMap = new HashMap<>();
                sbInfoMap.put("id", idT);
                sbInfoMap.put("sbip", sbip);
                sbInfoMap.put("sblx", sblx);
                sbInfoMap.put("sbxlh", sbxlh);
                sbMapList.add(sbInfoMap);
            }

            if (CollectionUtils.isEmpty(sbMapList)) {
                baseBean.writeLog("pushHrmToAppointDevice sbMapList is null.");
                result.put("code", "400");
                result.put("msg", "device info is null.");
                return result;
            }

            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            String modeId = rs.getPropValue("jzjg_zm_prop", "tssbjl_mode_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            String tbsbip = rs.getPropValue("jzjg_zm_prop", "tb_ip");

            rs.execute("SELECT loginid, lastname, departmentid, resourceimageid FROM HrmResource WHERE id in (" + id + ")");
            while (rs.next()) {
                String loginid = rs.getString("loginid");
                String lastname = rs.getString("lastname");
                if (StringUtils.isEmpty(loginid) || StringUtils.isEmpty(lastname)) {
                    continue;
                }
                String sfzhm = null;
                loginid = CommonUtil.removeLeadingZeros(loginid);
                if (StringUtils.isEmpty(loginid)) {
                    continue;
                }
                Map<String, Object> ksParamMap = new HashMap<>();
                String rytx = rs.getString("resourceimageid");
                for (Map<String, String> sbMap : sbMapList) {
                    String sbip = sbMap.get("sbip");
                    String sblx = sbMap.get("sblx");
                    String sbsn = sbMap.get("sbxlh");

                    String kqjId = sbMap.get("id");
                    // 如果是旷视，则先查询是否存在，存在则修改，不存在则新增
                    if (new BigDecimal(sblx).compareTo(new BigDecimal("1")) == 0) {
                        ksParamMap = new HashMap<>();
                        // 人员id
                        ksParamMap.put("id", loginid);
                        // 人员姓名
                        ksParamMap.put("person_name", lastname);
                        // 人员编号
                        ksParamMap.put("person_code", loginid);
                        // 身份证号码，需要aes加密
                        if (StringUtils.isNotEmpty(sfzhm)) {
                            ksParamMap.put("id_number", sfzhm);
                        }
                        // 人员头像
                        if (StringUtils.isNotEmpty(rytx)) {
                            ksParamMap.put("rytx", rytx);
                        }

                        boolean isExist = false;
                        String queryRes = queryHrmById(sbip, loginid, null);
                        try {
                            Map<String, Object> queryMap = gson.fromJson(queryRes, type);
                            if (queryMap.get("id") != null && StringUtils.equals(queryMap.get("id").toString(), loginid)) {
                                isExist = true;
                            }
                        } catch (Exception e) {
                        }
                        if (isExist) {
                            baseBean.writeLog("pushHrmToAppointDevice isExist:" + isExist + "、" + ksParamMap);
                            String uuid = UUID.randomUUID() + "-" + loginid;
                            rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                            "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?)",
                                    kqjId, JSONObject.toJSONString(ksParamMap), "3", "4", modeId, uuid, "1",
                                    "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                            continue;
//                            String dataId = null;
//                            rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
//                            if (rs1.next()) {
//                                dataId = rs1.getString("id");
//                            }
//                            updateHrmByIdKs(sbip, ksParamMap, dataId);
                        } else {
                            String uuid = UUID.randomUUID() + "-" + loginid;
                            rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                            "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?)",
                                    kqjId, JSONObject.toJSONString(ksParamMap), "0", "4", modeId, uuid, "1",
                                    "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                            String dataId = null;
                            rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                            if (rs1.next()) {
                                dataId = rs1.getString("id");
                            }
                            pushHrmToKs(sbip, ksParamMap, dataId);
                        }
                    }

                    if (new BigDecimal(sblx).compareTo(new BigDecimal("0")) == 0) {
                        sbip = tbsbip;
                        Map<String, Object> tbParamMap = new HashMap<>();
                        tbParamMap.put("SN", sbsn);
                        long taskId = System.currentTimeMillis();
                        tbParamMap.put("taskId", taskId);
                        Map<String, Object> tbParamMap_copy = new HashMap<>();
                        tbParamMap_copy.put("SN", sbsn);
                        tbParamMap_copy.put("taskId", taskId);
                        List<Map<String, Object>> mapList = new ArrayList<>();
                        List<Map<String, Object>> mapList_copy = new ArrayList<>();
                        Map<String, Object> mapTemp = new HashMap<>();
                        mapTemp.put("pin", loginid);
                        mapTemp.put("name", lastname);
                        mapTemp.put("userType", 0);
                        Map<String, Object> mapTemp_copy = new HashMap<>();
                        mapTemp_copy.put("pin", loginid);
                        mapTemp_copy.put("name", lastname);
                        mapTemp_copy.put("userType", 0);

                        if (StringUtils.isNotEmpty(rytx)) {
                            String imageBase64 = CommonUtil.imageBase64(Integer.parseInt(rytx));
                            mapTemp.put("photo", imageBase64);
                        }
                        mapList.add(mapTemp);
                        mapList_copy.add(mapTemp_copy);
                        tbParamMap.put("Data", mapList);
                        tbParamMap_copy.put("Data", mapList_copy);

                        String uuid = UUID.randomUUID() + "-" + loginid;
                        rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?)",
                                kqjId, JSONObject.toJSONString(tbParamMap_copy), "0", "4", modeId, uuid, "1",
                                "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                        String dataId = null;
                        rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                        if (rs1.next()) {
                            dataId = rs1.getString("id");
                        }
                        pushHrmToTb(sbip, tbParamMap, dataId);
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog("pushHrmToAppointDevice error:" + e);
            result.put("mes", "系统异常，请联系管理员！");
            result.put("code", "500");
            return result;
        }
        result.put("mes", "正在同步，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> delHrmInAppointDevice(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("delHrmInAppointDevice start:" + params);
        try {
            String id = Util.null2String(params.get("ryId"));
            String sbId = Util.null2String(params.get("sbId"));
            if (StringUtils.isEmpty(id) || StringUtils.isEmpty(sbId)) {
                baseBean.writeLog("delHrmInAppointDevice params is null.");
                result.put("code", "400");
                result.put("msg", "params is null.");
                return result;
            }
            List<Map<String, String>> sbMapList = new ArrayList<>();
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE id in (" + sbId + ")");
            while (rs.next()) {
                String idT = rs.getString("id");
                String sbip = rs.getString("sbip");
                String sblx = rs.getString("sblx");
                String sbxlh = rs.getString("sbxlh");
                if (StringUtils.isEmpty(sbip) || StringUtils.isEmpty(sblx) || StringUtils.isEmpty(id)) {
                    continue;
                }
                if (StringUtils.isEmpty(sbxlh)) {
                    sbxlh = "0";
                }
                Map<String, String> sbInfoMap = new HashMap<>();
                sbInfoMap.put("id", idT);
                sbInfoMap.put("sbip", sbip);
                sbInfoMap.put("sblx", sblx);
                sbInfoMap.put("sbxlh", sbxlh);
                sbMapList.add(sbInfoMap);
            }

            if (CollectionUtils.isEmpty(sbMapList)) {
                baseBean.writeLog("delHrmInAppointDevice sbMapList is null.");
                result.put("code", "400");
                result.put("msg", "device info is null.");
                return result;
            }

            String modeId = rs.getPropValue("jzjg_zm_prop", "tssbjl_mode_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            String tbsbip = rs.getPropValue("jzjg_zm_prop", "tb_ip");

            rs.execute("SELECT loginid, lastname, departmentid, resourceimageid FROM HrmResource WHERE id in (" + id + ")");
            while (rs.next()) {
                String loginid = rs.getString("loginid");
                if (StringUtils.isEmpty(loginid)) {
                    continue;
                }
                loginid = CommonUtil.removeLeadingZeros(loginid);
                if (StringUtils.isEmpty(loginid)) {
                    continue;
                }
                Map<String, Object> ksParamMap = new HashMap<>();
                for (Map<String, String> sbMap : sbMapList) {
                    String sbip = sbMap.get("sbip");
                    String sblx = sbMap.get("sblx");
                    String sbsn = sbMap.get("sbxlh");

                    String kqjId = sbMap.get("id");
                    // 如果是旷视，则先查询是否存在，存在则修改，不存在则新增
                    if (new BigDecimal(sblx).compareTo(new BigDecimal("1")) == 0) {
                        ksParamMap = new HashMap<>();
                        // 人员id
                        ksParamMap.put("id", loginid);
                        String uuid = UUID.randomUUID() + "-" + loginid;
                        rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,lztzid,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
                                kqjId, id, JSONObject.toJSONString(ksParamMap), "0", "5", modeId, uuid, "1",
                                "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                        String dataIdA = null;
                        rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                        if (rs1.next()) {
                            dataIdA = rs1.getString("id");
                        }
                        delHrmInKs(sbip, ksParamMap, dataIdA);
                    }

                    if (new BigDecimal(sblx).compareTo(new BigDecimal("0")) == 0) {
                        sbip = tbsbip;
                        Map<String, Object> tbParamMap = new HashMap<>();
                        tbParamMap.put("SN", sbsn);
                        tbParamMap.put("taskId", System.currentTimeMillis());

                        List<Map<String, String>> mapList = new ArrayList<>();
                        Map<String, String> mapTemp = new HashMap<>();
                        mapTemp.put("pin", loginid);
                        mapList.add(mapTemp);
                        tbParamMap.put("Data", mapList);

                        String uuid = UUID.randomUUID() + "-" + loginid;
                        rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,lztzid,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
                                kqjId, id, JSONObject.toJSONString(tbParamMap), "0", "5", modeId, uuid, "1",
                                "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                        String dataId = null;
                        rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                        if (rs1.next()) {
                            dataId = rs1.getString("id");
                        }
                        delHrmInTb(sbip, tbParamMap, dataId);
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog("delHrmInAppointDevice error:" + e);
            result.put("mes", "系统异常，请联系管理员！");
            result.put("code", "500");
            return result;
        }
        result.put("mes", "正在同步，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> delHrmInAppointDeviceNew(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("delHrmInAppointDeviceNew start:" + params);
        try {
            String idsParam = Util.null2String(params.get("idsParam"));
            if (StringUtils.isEmpty(idsParam)) {
                baseBean.writeLog("delHrmInAppointDeviceNew params is null.");
                result.put("code", "400");
                result.put("msg", "params is null.");
                return result;
            }
            Map<String, Map<String, String>> sbMapMap = new HashMap<>();
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb");
            while (rs.next()) {
                String idT = rs.getString("id");
                String sbip = rs.getString("sbip");
                String sblx = rs.getString("sblx");
                String sbxlh = rs.getString("sbxlh");
                if (StringUtils.isEmpty(sbip) || StringUtils.isEmpty(sblx) || StringUtils.isEmpty(idT) || StringUtils.isEmpty(sbxlh)) {
                    continue;
                }
                Map<String, String> sbInfoMap = new HashMap<>();
                sbInfoMap.put("id", idT);
                sbInfoMap.put("sbip", sbip);
                sbInfoMap.put("sblx", sblx);
                sbInfoMap.put("sbxlh", sbxlh);
                sbMapMap.put(sbxlh, sbInfoMap);
            }

            if (CollectionUtils.isEmpty(sbMapMap)) {
                baseBean.writeLog("delHrmInAppointDeviceNew sbMapMap is null.");
                result.put("code", "400");
                result.put("msg", "device info is null.");
                return result;
            }

            String modeId = rs.getPropValue("jzjg_zm_prop", "tssbjl_mode_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            String tbsbip = rs.getPropValue("jzjg_zm_prop", "tb_ip");

            rs.execute("SELECT id,rysbbh,szsbsn FROM uf_kqjryjlb WHERE id in (" + idsParam + ")");
            while (rs.next()) {
                String loginid = rs.getString("rysbbh");
                String szsbsn = rs.getString("szsbsn");
                String dataId = rs.getString("id");
                if (StringUtils.isEmpty(loginid) || StringUtils.isEmpty(szsbsn) || StringUtils.isEmpty(dataId)) {
                    continue;
                }
                Map<String, String> sbMap = sbMapMap.get(szsbsn);
                if (CollectionUtils.isEmpty(sbMap)) {
                    continue;
                }
                String sbip = sbMap.get("sbip");
                String sblx = sbMap.get("sblx");
                String sbsn = sbMap.get("sbxlh");
                String kqjId = sbMap.get("id");
                if (StringUtils.isEmpty(sblx) || StringUtils.isEmpty(kqjId)) {
                    continue;
                }
                loginid = CommonUtil.removeLeadingZeros(loginid);
                if (StringUtils.isEmpty(loginid)) {
                    continue;
                }
                Map<String, Object> ksParamMap = new HashMap<>();

                // 如果是旷视，则先查询是否存在，存在则修改，不存在则新增
                if (new BigDecimal(sblx).compareTo(new BigDecimal("1")) == 0) {
                    if (StringUtils.isEmpty(sbip)) {
                        continue;
                    }
                    ksParamMap = new HashMap<>();
                    // 人员id
                    ksParamMap.put("id", loginid);
                    String uuid = UUID.randomUUID() + "-" + loginid;
                    rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,sbrytzid,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                    "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
                            kqjId, dataId, JSONObject.toJSONString(ksParamMap), "0", "5", modeId, uuid, "1",
                            "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                    String dataIdA = null;
                    rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                    if (rs1.next()) {
                        dataIdA = rs1.getString("id");
                    }
                    delHrmInKs(sbip, ksParamMap, dataIdA);
                }

                if (new BigDecimal(sblx).compareTo(new BigDecimal("0")) == 0) {
                    if (StringUtils.isEmpty(sbsn)) {
                        continue;
                    }
                    sbip = tbsbip;
                    Map<String, Object> tbParamMap = new HashMap<>();
                    tbParamMap.put("SN", sbsn);
                    tbParamMap.put("taskId", System.currentTimeMillis());

                    List<Map<String, String>> mapList = new ArrayList<>();
                    Map<String, String> mapTemp = new HashMap<>();
                    mapTemp.put("pin", loginid);
                    mapList.add(mapTemp);
                    tbParamMap.put("Data", mapList);

                    String uuid = UUID.randomUUID() + "-" + loginid;
                    rs1.executeUpdate("INSERT INTO uf_tssbjlglb (sb,sbrytzid,qqcsjmq,zt,tslx, formmodeid,MODEUUID,modedatacreater," +
                                    "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
                            kqjId, dataId, JSONObject.toJSONString(tbParamMap), "0", "5", modeId, uuid, "1",
                            "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                    String dataIdTs = null;
                    rs1.executeQuery("SELECT id FROM uf_tssbjlglb WHERE MODEUUID = ?", uuid);
                    if (rs1.next()) {
                        dataIdTs = rs1.getString("id");
                    }
                    delHrmInTb(sbip, tbParamMap, dataIdTs);
                }
            }

            // 删除台账数据
            rs.execute("DELETE FROM uf_kqjryjlb WHERE id in (" + idsParam + ")");
        } catch (Exception e) {
            baseBean.writeLog("delHrmInAppointDeviceNew error:" + e);
            result.put("mes", "系统异常，请联系管理员！");
            result.put("code", "500");
            return result;
        }
        result.put("mes", "正在同步，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> getDeviceAllHrm(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("getDeviceAllHrm start:" + params);
        try {
            RecordSet rs = new RecordSet();
            // 获取考勤设备ip
            Map<String, String> ipMapKs = new HashMap<>();
            Map<String, String> sbwzMapKs = new HashMap<>();
            Map<String, String> ipMapTb = new HashMap<>();
            Map<String, String> ipMapZk = new HashMap<>();
            String tbIp = rs.getPropValue("jzjg_zm_prop", "tb_ip");
            rs.execute("SELECT * FROM uf_kqsbdzgxgljmb WHERE sbip is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String sbip = rs.getString("sbip");
                String sblx = rs.getString("sblx");
                String sbxlh = rs.getString("sbxlh");
                String sbwz = rs.getString("sbwz");
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                if (StringUtils.equals(sblx, "1") && StringUtils.isNotEmpty(sbip)) {
                    ipMapKs.put(id, sbip + "_" + sbxlh);
                    sbwzMapKs.put(id, sbwz);
                }
                if (StringUtils.equals(sblx, "0")) {
                    if (StringUtils.isEmpty(sbxlh)) {
                        continue;
                    }
                    ipMapTb.put(id, tbIp + "_" + sbxlh);
                }
                if (StringUtils.equals(sblx, "2") && StringUtils.isNotEmpty(sbip)) {
                    ipMapZk.put(id, sbip + "_" + sbxlh);
                }
            }
            if (CollectionUtils.isEmpty(ipMapKs) && CollectionUtils.isEmpty(ipMapTb) && CollectionUtils.isEmpty(ipMapZk)) {
                baseBean.writeLog("getDeviceAllHrm ip info is null.");
                result.put("mes", "设备为空！");
                result.put("code", "200");
                return result;
            }

            // 获取工号与id对应
            Map<String, String> ghAndIdMap = new HashMap<>();
            Map<String, String> ghAndWkMap = new HashMap<>();
            rs.execute("SELECT id, loginid, workcode FROM hrmresource WHERE workcode is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("loginid");
                String gh = rs.getString("workcode");
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                workcode = CommonUtil.removeLeadingZeros(workcode);
                if (StringUtils.isEmpty(workcode)) {
                    continue;
                }
                ghAndIdMap.put(workcode, id);
                ghAndWkMap.put(workcode, gh);
            }

            Gson gson = new Gson();
            Type type = new TypeToken<Map<String, Object>>() {
            }.getType();
            List<List> insertList = new ArrayList<>();
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            baseBean.writeLog("getDeviceAllHrm start to get ks.");
            // 旷视
            if (!CollectionUtils.isEmpty(ipMapKs)) {
                KsUtils ksUtils = new KsUtils();
                Set<String> oldDataSet = new HashSet<>();
                rs.execute("SELECT * FROM uf_kqjryjlb WHERE sblx = 0");
                while (rs.next()) {
                    String rysbbh = rs.getString("rysbbh");
                    String szsbsn = rs.getString("szsbsn");
                    String ryxm = rs.getString("ryxm");
                    if (StringUtils.isEmpty(rysbbh) || StringUtils.isEmpty(szsbsn) || StringUtils.isEmpty(ryxm)) {
                        continue;
                    }
                    oldDataSet.add(szsbsn + "_" + rysbbh + "_" + ryxm);
                }
                for (Map.Entry<String, String> entry : ipMapKs.entrySet()) {
                    String sbip = null;
                    try {
                        String sbid = entry.getKey();
                        String sbwz = sbwzMapKs.get(sbid);
                        String value = entry.getValue();
                        sbip = value.split("_")[0];
                        String sn = value.split("_")[1];
                        // 登陆鉴权挑战
                        String paramStr = ksUtils.loginChallenge("admin", sbip);
                        Map<String, Object> mapC = gson.fromJson(paramStr, type);

                        Object session_id = mapC.get("session_id");
                        Object challenge = mapC.get("challenge");
                        Object salt = mapC.get("salt");
                        if (Objects.isNull(session_id) || Objects.isNull(challenge) || Objects.isNull(salt)) {
                            baseBean.writeLog("getDeviceAllHrm login challenge failed.");
                            continue;
                        }
                        // 设备登陆
                        String loginRes = ksUtils.login(session_id.toString(), challenge.toString(), salt.toString(), sbip);
                        Map<String, Object> mapIn = gson.fromJson(loginRes, type);
                        Object sessionIdNew = mapIn.get("session_id");

                        Map<String, Object> paramMap = new HashMap<>();

                        int limit = 100;
                        int offset = 0;
                        paramMap.put("limit", limit);
                        paramMap.put("sort", "asc");
                        boolean isGoing = true;
                        while (isGoing) {
                            int offsetInt = offset * limit;
                            paramMap.put("offset", offsetInt);

                            String resultStr = HttpRequest.get("http://" + sbip + "/api/persons/query")
                                    .header(Header.CONTENT_TYPE, "application/json")
                                    .header(Header.COOKIE, "sessionID=" + sessionIdNew)
                                    .body(JSONObject.toJSONString(paramMap))
                                    .timeout(20000)
                                    .execute().body();

                            baseBean.writeLog("getDeviceAllHrm resultStr:" + resultStr);

                            if (StringUtils.isEmpty(resultStr)) {
                                isGoing = false;
                                break;
                            }
                            Map<String, Object> hrmMap = gson.fromJson(resultStr, type);
                            Object paging = hrmMap.get("paging");
                            if (Objects.isNull(paging)) {
                                isGoing = false;
                                break;
                            }
                            Map<String, Object> pageMap = gson.fromJson(paging.toString(), type);
                            Object total = pageMap.get("total");
                            if (Objects.isNull(total)) {
                                isGoing = false;
                                break;
                            }
                            Object limitObj = pageMap.get("limit");
                            if (Objects.isNull(limitObj)) {
                                isGoing = false;
                                break;
                            }
                            if (new BigDecimal("100").compareTo(new BigDecimal(limitObj.toString())) == 0 && new BigDecimal(String.valueOf(offsetInt)).compareTo(new BigDecimal(total.toString())) < 0) {
                                offset = offset + 1;
                            } else {
                                isGoing = false;
                            }
                            Object data = hrmMap.get("data");
                            if (Objects.isNull(data)) {
                                isGoing = false;
                                break;
                            }

                            List<Map<String, String>> mapList = (List<Map<String, String>>) data;
                            for (Map<String, String> map : mapList) {
                                String ygsbid = map.get("id");
                                String name = map.get("person_name");
                                String person_code = map.get("person_code");
                                if (StringUtils.isEmpty(name) || StringUtils.isEmpty(ygsbid) || StringUtils.isEmpty(person_code)) {
                                    continue;
                                }
                                if ((!CollectionUtils.isEmpty(oldDataSet)) && oldDataSet.contains(sn + "_" + person_code + "_" + name)) {
                                    continue;
                                }
                                String loginidTemp = person_code;
                                if (loginidTemp.length() == 4 && loginidTemp.startsWith("9")) {
                                    loginidTemp = "90" + loginidTemp;
                                }
                                String id = ghAndIdMap.get(loginidTemp);
                                String gh = ghAndWkMap.get(loginidTemp);
                                if (StringUtils.isEmpty(id)) {
                                    id = "0";
                                }
                                if (StringUtils.isEmpty(gh)) {
                                    gh = "0";
                                }
                                List list = new ArrayList();
                                list.add(ygsbid);
                                list.add(person_code);
                                list.add(name);
                                list.add(id);
                                list.add(gh);
                                list.add(sn);
                                list.add("0");
                                list.add("0");
                                list.add(sbwz);
                                list.add("146");
                                list.add(UUID.randomUUID().toString());
                                list.add("1");
                                list.add("0");
                                list.add(sdfDate.format(new Date()));
                                list.add(sdfTime.format(new Date()));
                                insertList.add(list);
                            }
                        }
                    } catch (Exception e) {
                        baseBean.writeLog("getDeviceAllHrm single error:" + sbip + "、" + e);
                    }
                }
            }

            baseBean.writeLog("getDeviceAllHrm start to get telpo.");
            // 天波
            if (!CollectionUtils.isEmpty(ipMapTb)) {
                for (Map.Entry<String, String> entry : ipMapTb.entrySet()) {
                    String sbid = entry.getKey();
                    String value = entry.getValue();
                    String ip = value.split("_")[0];
                    String sn = value.split("_")[1];

                    Map<String, Object> paramMap = new HashMap<>();
                    List<String> snList = new ArrayList<>();
                    snList.add(sn);
                    paramMap.put("SN", snList);
                    long taskId = System.currentTimeMillis();
                    paramMap.put("taskId", taskId);
                    paramMap.put("type", "queryUsers");
                    Map<String, Object> mapTemp = new HashMap<>();
                    mapTemp.put("photo", 0);
                    paramMap.put("Data", mapTemp);

                    String url = "http://" + ip + ":1820/Face/sendControl";
                    String resultRes = HttpRequest.post(url)
                            .header(Header.CONTENT_TYPE, "application/json")
                            .body(JSONObject.toJSONString(paramMap))
                            .timeout(20000)
                            .execute().body();
                    baseBean.writeLog("getDeviceAllHrm resultRes、taskId:" + resultRes + "、" + taskId);
                    Thread.sleep(5000);
                }
            }

            if (!CollectionUtils.isEmpty(insertList)) {
                baseBean.writeLog("getDeviceAllHrm insertList size is:" + insertList.size());
                String insertSql = "INSERT INTO uf_kqjryjlb (rysbid, rysbbh, ryxm, ygxm, yggh, szsbsn, sblx, sjlx, sbwz, " +
                        "formmodeid,MODEUUID,modedatacreater,modedatacreatertype, modedatacreatedate, modedatacreatetime) " +
                        "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                rs.executeBatchSql(insertSql, insertList);
            }
            baseBean.writeLog("getDeviceAllHrm end.");
        } catch (Exception e) {
            baseBean.writeLog("getDeviceAllHrm error:" + e);
            result.put("mes", "系统异常，请联系管理员！");
            result.put("code", "500");
            return result;
        }
        result.put("mes", "正在同步，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> handlePushUsersData(Map<String, Object> params) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", "00");
        baseBean.writeLog("handlePushUsersData start.");
        RecordSet rs = new RecordSet();
        try {
            if (CollectionUtils.isEmpty(params)) {
                baseBean.writeLog("handlePushUsersData params is null.");
                return resultMap;
            }
            baseBean.writeLog("handlePushUsersData params is:" + JSONObject.toJSONString(params));

            Object sn = params.get("SN");
            if (sn == null) {
                return resultMap;
            }

            Object data = params.get("data");
            if (data == null) {
                return resultMap;
            }
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) data;

            if (CollectionUtils.isEmpty(mapList)) {
                return resultMap;
            }
            baseBean.writeLog("handlePushUsersData mapList is:" + mapList.size());
            // 获取工号与id对应
            Map<String, String> ghAndIdMap = new HashMap<>();
            Map<String, String> ghAndWkMap = new HashMap<>();
            rs.execute("SELECT id, loginid, workcode FROM hrmresource WHERE workcode is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("loginid");
                String gh = rs.getString("workcode");
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                workcode = CommonUtil.removeLeadingZeros(workcode);
                if (StringUtils.isEmpty(workcode)) {
                    continue;
                }
                ghAndIdMap.put(workcode, id);
                ghAndWkMap.put(workcode, gh);
            }
            if (CollectionUtils.isEmpty(ghAndIdMap)) {
                return resultMap;
            }

            String sbwz = null;
            rs.executeQuery("SELECT sbwz FROM uf_kqsbdzgxgljmb WHERE sbxlh = ?", sn);
            if (rs.next()) {
                sbwz = rs.getString("sbwz");
            }

            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");

            Set<String> oldDataSet = new HashSet<>();
            rs.execute("SELECT * FROM uf_kqjryjlb WHERE sblx = 1");
            while (rs.next()) {
                String rysbbh = rs.getString("rysbbh");
                String szsbsn = rs.getString("szsbsn");
                String ryxm = rs.getString("ryxm");
                if (StringUtils.isEmpty(rysbbh) || StringUtils.isEmpty(szsbsn) || StringUtils.isEmpty(ryxm)) {
                    continue;
                }
                oldDataSet.add(szsbsn + "_" + rysbbh + "_" + ryxm);
            }

            List<List> insertList = new ArrayList<>();
            for (Map<String, Object> map : mapList) {
                Object pinObj = map.get("pin");
                Object nameObj = map.get("name");
                if (Objects.isNull(pinObj)) {
                    continue;
                }
                if ((!CollectionUtils.isEmpty(oldDataSet)) && oldDataSet.contains(sn + "_" + pinObj + "_" + nameObj)) {
                    continue;
                }
                String pin = pinObj.toString();
                if (pin.length() == 4 && pin.startsWith("9")) {
                    pin = "90" + pin;
                }
                pin = CommonUtil.removeLeadingZeros(pin);
                if (StringUtils.isEmpty(pin)) {
                    continue;
                }
                String id = ghAndIdMap.get(pin);
                String gh = ghAndWkMap.get(pin);
                List list = new ArrayList();
                list.add(pinObj.toString());
                list.add(pinObj.toString());
                list.add(nameObj);
                list.add(id);
                list.add(gh);
                list.add(sn);
                list.add("1");
                list.add("0");
                list.add(sbwz);
                list.add("146");
                list.add(UUID.randomUUID().toString());
                list.add("1");
                list.add("0");
                list.add(sdfDate.format(new Date()));
                list.add(sdfTime.format(new Date()));
                insertList.add(list);
            }

            if (!CollectionUtils.isEmpty(insertList)) {
                baseBean.writeLog("handlePushUsersData insertList size is:" + insertList.size());
                String insertSql = "INSERT INTO uf_kqjryjlb (rysbid, rysbbh, ryxm, ygxm, yggh, szsbsn, sblx, sjlx, sbwz, " +
                        "formmodeid,MODEUUID,modedatacreater,modedatacreatertype, modedatacreatedate, modedatacreatetime) " +
                        "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                rs.executeBatchSql(insertSql, insertList);
            }
            baseBean.writeLog("handlePushUsersData end.");
        } catch (Exception e) {
            baseBean.writeLog("handlePushUsersData error:" + e);
        }

        return resultMap;
    }

    @Override
    public Map<String, Object> canteenPushAgain(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("canteenPushAgain start:" + params);
        try {
            String ids = Util.null2String(params.get("ids"));
            if (StringUtils.isEmpty(ids)) {
                baseBean.writeLog("canteenPushAgain ids is null.");
                result.put("code", "400");
                result.put("msg", "ids is null.");
                return result;
            }
            RecordSet rs = new RecordSet();
            String[] idArr = ids.split(",");
            for (String id : idArr) {
                rs.execute("SELECT * FROM uf_lncytsjlb WHERE id = " + id);
                if (rs.next()) {
                    String jkurl = rs.getString("jkurl");
                    String qqcs = rs.getString("qqcs");

                    if (StringUtils.isEmpty(qqcs) || StringUtils.isEmpty(jkurl)) {
                        baseBean.writeLog("canteenPushAgain param is null.");
                        result.put("code", "400");
                        result.put("msg", "param is null.");
                        return result;
                    }

                    Gson gson = new Gson();
                    Type type = new TypeToken<List<Map<String, String>>>() {
                    }.getType();
                    List<Map<String, String>> bodyMapList = gson.fromJson(qqcs, type);
                    baseBean.writeLog("canteenPushAgain bodyMapList is:" + bodyMapList);
                    pushLeopen(bodyMapList, jkurl, id);
                }
            }
        } catch (Exception e) {
            baseBean.writeLog("canteenPushAgain error:" + e);
        }
        result.put("code", "200");
        return result;
    }

    public void pushLeopen(List<Map<String, String>> bodyMapList, String url, String dataId) {
        baseBean.writeLog("pushLeopen start:" + url + "、" + dataId);
        RecordSet createRs = new RecordSet();
        try {
            String appid = createRs.getPropValue("jzjg_canteen_zm_prop", "canteen_appid");
            String appsecret = createRs.getPropValue("jzjg_canteen_zm_prop", "canteen_appsecret");
            //请求内容字典排序，转换为String
            String content = JSON.toJSONString(bodyMapList, SerializerFeature.MapSortField, SerializerFeature.WriteMapNullValue);

            //构造请求验签参数
            Map<String, Object> map = new TreeMap<>();
            map.put("appid", appid);
            map.put("version", "1.0.0");
            map.put("signtype", "md5");
            map.put("timestamp", String.valueOf(System.currentTimeMillis()));
            map.put("nonce", RandomUtil.randomNumbers(10));
            map.put("content", content);
            //生成sign，防篡改
            String toSignStr = Joiner.on("&")
                    .useForNull("")
                    .withKeyValueSeparator("=")
                    .join(map) + "&appsecret=" + appsecret;


            // md5/sha256 加签（其他方式待提供）
            String sign = DigestUtils.md5Hex(toSignStr).toUpperCase();

            map.put("sign", sign);

            //post请求
            map.replace("content", bodyMapList);
            String host = createRs.getPropValue("jzjg_canteen_zm_prop", "canteen_host");
            HttpRequest request = HttpUtil.createPost(host + url);
            request.body(JSONUtil.toJsonStr(map), ContentType.JSON.toString());
            HttpResponse response = request.execute();

            //返回值验签
            Map<String, Object> resultMap = JSON.parseObject(
                    response.body(),
                    new TypeReference<SortedMap<String, Object>>() {
                    }.getType()
            );
            createRs.executeUpdate("UPDATE uf_lncytsjlb SET xyjg = ? WHERE id = ?", JSONObject.toJSONString(resultMap), dataId);
            Object code = resultMap.get("code");
            if (code != null && (StringUtils.equals(code.toString(), "200") || StringUtils.equals(code.toString(), "10000"))) {
                createRs.executeUpdate("UPDATE uf_lncytsjlb SET zt = 0 WHERE id = ?", dataId);
            } else {
                createRs.executeUpdate("UPDATE uf_lncytsjlb SET zt = 1 WHERE id = ?", dataId);
            }
        } catch (Exception e) {
            createRs.executeUpdate("UPDATE uf_lncytsjlb SET ycyy = ? WHERE id = ?", e, dataId);
        }
        baseBean.writeLog("pushLeopen end.");
    }
}
